Author: Charles Tapley Hoyt
Estimated Run Time: 45 seconds
This notebook shows how to combine multiple graphs from different sources and summarize them together. This might be useful during projects where multiple curators are creating BEL scripts that should be joined for scientific use, but for provenance, should be kept separate.
In [1]:
import os
import time
import sys
import pybel
import pybel_tools
from pybel_tools.summary import info_str
In [2]:
print(sys.version)
In [3]:
print(time.asctime())
In [4]:
pybel.utils.get_version()
Out[4]:
In [5]:
pybel_tools.utils.get_version()
Out[5]:
In [6]:
bms_base = os.environ['BMS_BASE']
In [7]:
human_dir = os.path.join(bms_base, 'cbn', 'Human-2.0')
mouse_dir = os.path.join(bms_base, 'cbn', 'Mouse-2.0')
rat_dir = os.path.join(bms_base, 'cbn', 'Rat-2.0')
In [8]:
%%time
graphs = []
for d in (human_dir, mouse_dir, rat_dir):
for p in os.listdir(d):
if not p.endswith('gpickle'):
continue
path = os.path.join(d, p)
g = pybel.from_pickle(path)
graphs.append(g)
In [9]:
len(graphs)
Out[9]:
The graphs are combine with the union function, which retains all node and edges from each graph
In [10]:
%%time
combine = pybel.struct.union(graphs)
In [11]:
print(info_str(combine))